package QQclient;

import QQcommon.Massage_2;
import QQcommon.Message;
import QQcommon.User_qq;
import Service.Massage_Thread;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;


    public class UserclientService {
        User_qq user=new User_qq();
        boolean b=false;
        private Socket socket;

        public boolean checkUser(String UserId,String pwd){
            user.setUserId(UserId);
            user.setPwd(pwd);
            try {
                socket=new Socket(InetAddress.getLocalHost(), Integer.parseInt("9999"));
                ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
                oos.writeObject(user);//发送user对象

                ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
                Message mes=(Message) ois.readObject();//接收服务端发回的信息

                if(mes.getMassageType().equals(Massage_2.Massage_LogIn_success)){//登录成功
                    ClientThread clientThread=new ClientThread(socket);
                    clientThread.start();
                    Thread_Hashmap.Add_Tread(UserId,clientThread);//加入集合中
                    b=true;
                }else {
                    socket.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return b;
        }
    }


